//
// Created by 11401 on 25-7-15.
//

#include "ic_task.h"

//10个球
id_bo id_ball[10];
void app_ic_cade_task(void *argument)
{
    uint8_t w[30];
    uint8_t data;
    bsp_ast522_Request();
    for(;;)
    {
        //任务通知
        static uint8_t i =0;
        sprintf(w,"id : %d",i);
        ILI9341_DispStringLine_EN(LINE(2),(char *)w);
        //等待中断队列传回消息
        ILI9341_DispStringLine_EN(LINE(4),(char* )"oxcc");

        uint8_t ic_rx_data=0;
        xQueueReceive(ic_rx_packHandle,&ic_rx_data,portMAX_DELAY);
            switch (ic_rx_data)
            {
            case'a':
                //请求
                ILI9341_DispStringLine_EN(LINE(4),(char* )"oxcc");
                bsp_ast522_Request();
                break;
            case'b':
                //请求成功，发送防碰撞
                ILI9341_DispStringLine_EN(LINE(5),(char* )"ox08");
                bsp_ast522_PiccAnticoll();
                break;
            case'c':
                ILI9341_DispStringLine_EN(LINE(6),(char* )"ox0a");
                //获取id
                if (ats522.rx_buffer[1]==0x02)
                {
                    id_ball[i].id[0]=ats522_rx_bueff[4];
                    id_ball[i].id[1]=ats522_rx_bueff[5];
                    id_ball[i].id[2]=ats522_rx_bueff[6];
                    id_ball[i].id[3]=ats522_rx_bueff[7];
                }
                sprintf(w,"%d,%d,%d,%d",ats522_rx_bueff[4],ats522_rx_bueff[5],ats522_rx_bueff[6],ats522_rx_bueff[7]);
                ILI9341_DispStringLine_EN(LINE(7),w);
                //发送选择
                bsp_ats522_PiccSelect(id_ball[i].id[0],id_ball[i].id[1],id_ball[i].id[2],id_ball[i].id[3]);
                break;
            case 'd':
                ILI9341_DispStringLine_EN(LINE(8),(char* )"ox07");
                uint8_t key[6]={0xFF, 0xFF,0xFF, 0xFF,0xFF, 0xFF};
                bsp_ats522_PiccAuthKey(0x60,
                                           id_ball[i].id[0],id_ball[i].id[1],
                                           id_ball[i].id[2],id_ball[i].id[3],
                                           key,
                                           0x04);
                HAL_Delay(10);
                ILI9341_DispStringLine_EN(LINE(9),(char* )"ox06");
                bsp_ats522_Read(4);
                break;

            case'f':
                ILI9341_DispStringLine_EN(LINE(10),(char* )"ox16");
                id_ball[i].data=ats522_rx_bueff[5];
                break;
            }
        HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
        vTaskDelay(1);
    }

}